#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <QStringListModel>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // 设置窗口为无边框
    //setWindowFlags(Qt::FramelessWindowHint);

    //setStyleSheet("QMainWindow { background-color: rgb(249, 240, 244); }"); //默认标题栏颜色

    setStyleSheet("QMainWindow { background-color: rgb(246, 252, 255); }"); //HiAudioStudioTool默认颜色

    ui->stackedWidget->setStyleSheet("QWidget { background-color: white; }"); //需设置QMainWindow颜色,否则内部控件会变化(首页可以)

    ui->stackedWidget->setCurrentIndex(0);

    // QListView的使用 本文链接：https://blog.csdn.net/sinat_31608641/article/details/126088067
    // QStringListModel的使用
    QStringList strlist;

    strlist.append("首 页");
    strlist.append("AT命令收发");
    strlist.append("AT循环发送");

    QStringListModel *Model = new QStringListModel(strlist);

    QString strStyle;
    strStyle += "QWidget { background-color: rgb(246, 252, 255); }";
    strStyle += "QListView { font: 75 10pt ; }";
    strStyle += "QListView { border: none; }";
    strStyle += "QListView::item { padding: 5px; }";
    strStyle += "QListView::item:selected:!active { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(32, 84, 184, 255), stop:1 rgba(255, 255, 255, 255));}"; //选择其他控件时
    strStyle += "QListView::item:selected:active { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(32, 84, 184, 255), stop:1 rgba(255, 255, 255, 255));}";
    //strStyle += "QListView::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #FAFBFE, stop: 1 #DCDEF1); }"; //靠近

    ui->listView->setStyleSheet(strStyle);

    ui->listView->setModel(Model); // listview设置Model
    // listView绑定事件
    connect(ui->listView,SIGNAL(clicked(QModelIndex)),this,SLOT(slot_listView_event(QModelIndex)));

    //connect(ui->listWidget, SIGNAL(clicked(QModelIndex), this, SLOT(onListItemClicked(QListWidgetItem *)); //QListWidgetItem *item

    connect(ui->listWidget,SIGNAL(itemClicked(QListWidgetItem *)),this,SLOT(slot_listWidget_event(QListWidgetItem *)));


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::slot_listView_event(QModelIndex index)
{
    QString str = index.data().toString();
    int row = index.row();
    qDebug() << "row: " << row << "str: " << str;

    ui->stackedWidget->setCurrentIndex(row);
}

void MainWindow::slot_listWidget_event(QListWidgetItem *item)
{
    qDebug() << "Clicked item:" << item->text();
    QString str = item->text();

//    int row = item->data();
//    qDebug() << "row: " << row << "str: " << str;
//    ui->stackedWidget->setCurrentIndex(row);
}


void MainWindow::on_pushButton_2_clicked()
{

}
